﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;

using ERPStore.Extensions;
using ERPStore.Web.Extensions;
using ERPStore.Offers.Repositories;

namespace ERPStore.Offers.Controllers
{
	public class OffersApiController : ApiController
	{
		public OffersApiController(Services.OffersService offerService)
		{
			OfferService = offerService;
		}

		protected Services.OffersService OfferService { get; private set; }

		public IEnumerable<ERPStore.Models.Product> GetProductList([FromUri]ViewModels.Filter filter)
		{
			if (filter == null)
			{
				return null;
			}
			var offer = OfferService.GetOfferByLink(filter.OfferLink) as Models.OfferEx;
			if (offer == null)
			{
				return null;
			}

			int count = 0;
			var pagedList = OfferService.GetProductList(offer, filter.PageIndex, filter.PageSize, filter.CategoryCode, filter.BrandName, out count);

			return pagedList;
		}
	}
}
